package com.yunchen.BooksManagementSystem.manage.servlet;

import com.alibaba.fastjson.JSON;
import com.yunchen.BooksManagementSystem.manage.dao.adminDaoImpl;
import com.yunchen.BooksManagementSystem.manage.entity.borrowingRecord;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;

@WebServlet(name = "UserReturnApplyServlet",value = "/UserReturnApplyServlet")
public class UserReturnApplyServlet extends HttpServlet {
    private adminDaoImpl ad=new adminDaoImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ArrayList<borrowingRecord> br=null;
        try {
            br=ad.userReturnApply();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        String jsonString= JSON.toJSONString(br);
        resp.setContentType("text/json;charset=UTF-8");
        resp.getWriter().write(jsonString);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
